import BaseModel from './.model';
import { Table, Column, DataType, BelongsTo, HasMany, ForeignKey } from 'sequelize-typescript';
import AddressModel from './address.model';
import UserModel from './user.model';
import OrderItemModel from './order-item.model';

@Table({ tableName: 'orders' })
export default class OrderModel extends BaseModel {
  /** 收货地址的ID */
  @ForeignKey(() => AddressModel)
  @Column({ type: DataType.UUID, comment: '收货地址的ID' })
  addressId!: string;

  /** 订单取消的原因 */
  @Column({ type: DataType.STRING, allowNull: true, comment: '订单取消的原因' })
  cancelReason?: string;

  /** 订单完成的时间 */
  @Column({ type: DataType.DATE, allowNull: true, comment: '订单完成的时间' })
  completedTime?: Date;

  /** 订单的状态 */
  @Column({ type: DataType.ENUM('待处理', '处理中', '已完成', '已取消'), comment: '订单的状态' })
  orderStatus!: string;

  /** 支付方式 */
  @Column({ type: DataType.STRING, allowNull: true, comment: '支付方式' })
  paymentMethod?: string;

  /** 支付完成的时间 */
  @Column({ type: DataType.DATE, allowNull: true, comment: '支付完成的时间' })
  paymentTime?: Date;

  /** 物流单号 */
  @Column({ type: DataType.STRING, allowNull: true, comment: '物流单号' })
  trackingNumber?: string;

  /** 下单用户的ID */
  @ForeignKey(() => UserModel)
  @Column({ type: DataType.UUID, comment: '下单用户的ID' })
  userId!: string;

  /** 收货地址信息 */
  @BelongsTo(() => AddressModel)
  address?: AddressModel;

  /** 下单用户信息 */
  @BelongsTo(() => UserModel)
  user?: UserModel;

  /** 订单项列表 */
  @HasMany(() => OrderItemModel)
  orderItems?: OrderItemModel[];
}
